
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:get_storage/get_storage.dart';
import '../../api/system/menu.dart';
import '../../init_context.dart';
import 'menu_controller.dart';


class UserController extends GetxController{
    bool _isLogin=false;
    bool get isLogin =>_isLogin;

    set isLogin(login){
      _isLogin = login;
      update();
    }
    checkIsLogin(){
      if(!this.isLogin){
        final user= GetStorage("user");
        this.isLogin = user.hasData("access_token");
      }
    }
    setUserState(object){
      final user= GetStorage("user");
      user.write("info", object["data"]["user"]);
      user.write("access_token", object["data"]["access_token"]);
      this.isLogin = true;
    }
    loginSucccess()async{
      MenuProvider provider = Get.find();
      Response res =  await provider.menuList();
      final Map<String, dynamic> object = decoder.convert(res.bodyString.toString());
      if(object["code"]==0){
        MenuController menuController = Get.put(MenuController());
        menuController.menuList=object["data"];
      }
    }
    void onReady(){
      super.onReady();
    }

}